<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="帅哥" onclick="f(1)">
<input type="button" value="美女" onclick="f(2)">
<hr>

<script>
  function f(x) {
    let count =0;
    while (true){
      let url = x==1?"h.jpg":"../1.jpg";
      let img = document.createElement("img");
      let l =document.querySelector("input");
      img.src =url;
      document.body.append(img);
      count++;
      if (l.value==count){
        break;
      }
    }
  }
</script>
</body>
</html>